#include "Tait.h"

// Initialize Tait's starting variables
Tait::Tait(int locx, int locy, int locz, vector<vector<vector<Floor*>>> floor)
{
	collision = false;
	dir = NODIR;
	theFloor = floor;
	x = locx;
	y = locy;
	z = locz;
	type = TAIT;
	removeable = false;
}

Tait::~Tait(void)
{
}



//
//Virtual Methods
//
/*
void Tait::doTimeStep()
{
	//Tait is not capable of moving on his own (he's lazy)
}*/

void Tait::collide(Object* collider)
{

}

void Tait::collideWith(Object* collidee){

	// if Tait is collided with move him in the appropriate direction
	move(dir);
	collision = false;

}

void Tait::buttonPress() //For levers
{
	//Nothing
}



//Tait can walk on most floor types, but cant go through walls or blocks created from floors
bool Tait::legalFloor(){
	FloorType nextFloor;
	FloorState floorState;
	FloorType currentFloor = theFloor[x][y][z]->getType();
	if(bounds()){
		switch(dir){
		case UP:	
			nextFloor = theFloor[x][y-1][z]->getType();
			floorState = theFloor[x][y-1][z]->getFloorState();
			return  !(nextFloor == WSOUTH) && !(currentFloor == WNORTH) &&!(floorState == BLOCKCREATED);
			break;
		case DOWN:	
			nextFloor = theFloor[x][y+1][z]->getType();
			floorState = theFloor[x][y+1][z]->getFloorState();
			return  !(nextFloor == WNORTH)&& !(currentFloor == WSOUTH)&&!(floorState == BLOCKCREATED);
			break;
		case RIGHT:	
			nextFloor = theFloor[x+1][y][z]->getType();
			floorState = theFloor[x+1][y][z]->getFloorState();
			return  !(nextFloor == WWEST)&& !(currentFloor == WEAST)&&!(floorState == BLOCKCREATED);
			break;
		case LEFT:	
			nextFloor = theFloor[x-1][y][z]->getType();
			floorState = theFloor[x-1][y][z]->getFloorState();
			return  !(nextFloor == WEAST)&& !(currentFloor == WWEST)&&!(floorState == BLOCKCREATED);
			break;

		}
	}
	return false;
}

void Tait::doFloor(Equip currentEquip){

	condition = FINE;
	//sliding will set you into sliding unless you're against a wall
	if(theFloor[x][y][z] ->getType() == ICE && currentEquip!=ICESKATES){
		if(!checkCollide()&&bounds()){
			condition = SLIDING;
			move(dir);
		}
	}

	//
	//Slides tait in the appropriate direction of the floor
	//
	if(theFloor[x][y][z] ->getType() == FORCE && currentEquip!=SUCTIONCUPS){
		switch(theFloor[x][y][z] ->getFloorState()){
			case UPFLOOR:
				dir = UP;
				break;
			case DOWNFLOOR:
				dir = DOWN;
				break;
			case RIGHTFLOOR:
				dir = RIGHT;
				break;
			case LEFTFLOOR:
				dir = LEFT;
				break;
		}
		if(!checkCollide()&&bounds()){
			condition = SLIDING;
			switch(theFloor[x][y][z] ->getFloorState()){
			case UPFLOOR:
				move(UP);
				break;
			case RIGHTFLOOR:
				move(RIGHT);
				break;
			case DOWNFLOOR:
				move(DOWN);
				break;
			case LEFTFLOOR:
				move(LEFT);
				break;
			}
		}
	}





}

